function checkbox_slider_plot(data_origin, offset, step_size, num_motors, fig_name)
    % data_origin: 14×96×n 的三维数组
    % offset: 每次实验的横坐标偏移量
    % fig_name: 图像名称
    
    % 解析data_origin, 去掉最后一列时间
    data_origin = data_origin(1:end-1, :);
    data_origin_size = size(data_origin);
    data = reshape(data_origin, num_motors, [], data_origin_size(2));

    
    % 生成颜色和标记
    colors = lines(num_motors);
    markers = {'o', 's', 'd', '^', 'v', 'p', 'h', '>', '<', 'o', 's', 'd', '^', 'v'};
    
    % 创建图像并设置名称
    figure('Name', fig_name, 'NumberTitle', 'off');
    hold on;
    
    % 创建复选框 UI
    checkboxes = gobjects(num_motors, 1);
    for i = 1:num_motors
        checkboxes(i) = uicontrol('Style', 'checkbox', 'String', sprintf('Motor %d', i), ...
                                  'Value', 0, 'FontSize', 15, 'Units', 'normalized', ...
                                  'Position', [0.03, 0.9 - 0.05 * (i - 1), 0.07, 0.05], ...
                                  'Callback', @(src, event) updatePlot());
    end
    
    % 创建滑块 UI
    % slider = uicontrol('Style', 'slider', 'Min', 1, ...
    %                    'Max', max(1, size(data, 3) - step_size + 1), ...
    %                    'Value', 1, 'Units', 'normalized', ...
    %                    'Position', [0.03, 0.02, 0.2, 0.05], ...
    %                    'Callback', @(src, event) updatePlot());

    % 创建滑块 UI
    slider = uicontrol('Style', 'slider', 'Min', 1, ...
                       'Max', max(1, size(data, 3) - step_size + 1), ...
                       'Value', 1, 'Units', 'normalized', ...
                       'Position', [0.03, 0.02, 0.2, 0.05]);
    
    % 添加监听器，实现滑动过程中实时更新
    addlistener(slider, 'ContinuousValueChange', @(src, event) updatePlot());
    
    % 仍然保留原来的 Callback 以确保兼容
    slider.Callback = @(src, event) updatePlot();

    % 初始绘制
    plotHandles = gobjects(num_motors, step_size);
    updatePlot();
        
    function updatePlot()
        cla; % 清除当前axes中的所有图形
        hold on;
        selected_motors = [];
        
        for i = 1:num_motors
            if checkboxes(i).Value == 1
                selected_motors = [selected_motors, i];
                
                % 生成颜色梯度
                color_gradient = linspace(0.6, 1, step_size)';
                motor_colors = min(colors(i, :) .* color_gradient, 1);
                
                % 获取滑块的当前值
                start_idx = round(slider.Value);
                
                % 重新绘制 start_idx 的所有实验数据
                for k_idx = 1:step_size
                    k = start_idx + k_idx - 1;
                    if k > size(data, 3)
                        break;
                    end
                    x = (1:96) + offset * (k - 1);
                    y = squeeze(data(i, :, k));
                    
                    plotHandles(i, k_idx) = plot(x, y, 'Color', motor_colors(k_idx, :), ...
                        'Marker', markers{mod(i-1, length(markers)) + 1}, ...
                        'LineStyle', '-', 'LineWidth', 1.5, 'MarkerSize', 3, ...
                        'MarkerFaceColor', motor_colors(k_idx, :), ...
                        'MarkerEdgeColor', motor_colors(k_idx, :));
                end
            end
        end
        
        % 更新 legend
        if ~isempty(selected_motors)
            legend(arrayfun(@(i) sprintf('Motor %d', i), selected_motors, 'UniformOutput', false), 'Location', 'bestoutside');
        else
            legend off;
        end
        
        hold off;
    end
    
    % 设置图像属性
    xlabel('Time Step (with Offset)');
    ylabel('Value');
    title(fig_name);
    grid on;
end
